package com.emep.changzhi.analyse.http.aqi;

import com.emep.changzhi.analyse.entity.aqi.AreaAqiMoniter;
import com.emep.changzhi.analyse.entity.aqi.DataAqiInfo;
import com.emep.changzhi.analyse.model.ResultBean;
import com.emep.changzhi.analyse.service.aqi.AqiRealTimeService;
import com.emep.changzhi.analyse.utils.Constant;
import com.emep.changzhi.analyse.utils.DataValidator;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("air")
@Api(value = "airRealTimeController",tags = "获取实时空气质量柱状图")
public class AqiRealTimeController {
    @Autowired
    private AqiRealTimeService aqiRealTimeService;

    @ApiOperation(value = "获取实时空气质量柱状图", notes = "获取实时空气质量柱状图")
    @ApiResponses({@ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足")})
    @ApiImplicitParams({
            @ApiImplicitParam(name = "area_id", value = "城市名称汉字", required = true, dataType = "String", paramType = "query")
    })
    @GetMapping(value = "realtime")

    public ResultBean<DataAqiInfo> findweather(@RequestParam Map<String, Object> payload) {
        ResultBean result = DataValidator.validateMapData(payload, "area_id");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS) {
            Map<String, Object> weathers = aqiRealTimeService.list(payload.get("area_id").toString());
            return result.ok(weathers);
        }
        return result;

    }


    @ApiOperation(value="获取首页实时空气质量", notes="获取首页实时空气质量")
    @ApiResponses({ @ApiResponse(code = 1, message = "操作成功"),
            @ApiResponse(code = 0, message = "操作失败，服务器内部异常"),
            @ApiResponse(code = 303, message = "权限不足") })
    @ApiImplicitParams({
            @ApiImplicitParam(name = "area_id", value = "城市名称汉字", required = true, dataType = "String",paramType="query")
    })
    @GetMapping(value = "realTimeOne")
    public ResultBean<DataAqiInfo> findweather1(@RequestParam Map<String, Object> payload){
        ResultBean result = DataValidator.validateMapData(payload, "area_id");
        if (result.getCode() == Constant.RESULT_CODE_SUCCESS){
            List<AreaAqiMoniter> weathers = aqiRealTimeService.realtime(payload.get("area_id").toString());
            return result.ok(weathers);
        }
        return  result;
    }
}
